package com.controller.model;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import com.model.Notification;

public class NotificationDataModel extends ListDataModel<Notification>
		implements SelectableDataModel<Notification> {
	public NotificationDataModel() {
	}

	public NotificationDataModel(List<Notification> data) {
		super(data);
	}

	public Notification getRowData(String rowKey) {
		// In a real app, a more efficient way like a query by rowKey should be
		// implemented to deal with huge data

		List<Notification> notifications = (List<Notification>) getWrappedData();

		for (Notification notification : notifications) {
			if (String.valueOf(notification.getId()).equals(rowKey))
				return notification;
		}

		return null;
	}

	public Object getRowKey(Notification notification) {
		return notification.getId();
	}
}
